package com.huangpuweb.task.service.imp;

import com.huangpuweb.task.model.*;
import com.huangpuweb.task.service.SyncSysDataService;
import com.huangpuweb.task.util.StringUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.wiring.BeanWiringInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class SyncSysDataServiceImp extends BaseSysDataServiceImp implements SyncSysDataService {


    @Override
    public void insertSysRefinedCrowdSituation(SysRefinedCrowdSituation sysrefinedcrowd) {
        String sql = "insert into sys_refined_crowdSituation(id,spotName,spotCode,realtimeNumber,totalNumber,createTime,updateTime,dataSources,remarks) values(?,?,?,?,?,?,?,?,?)";
        update(sql, new Object[]{sysrefinedcrowd.getId(), sysrefinedcrowd.getSpotName(), sysrefinedcrowd.getSpotCode(), sysrefinedcrowd.getRealtimeNumber(), sysrefinedcrowd.getTotalNumber(), sysrefinedcrowd.getCreateTime(), sysrefinedcrowd.getUpdateTime(), sysrefinedcrowd.getDataSources(), sysrefinedcrowd.getRemarks()});
    }

    @Override
    public void insertSysBackupCrowdSituation(SysRefinedCrowdSituation sysrefinedcrowd) {
        String sql = "insert into sys_backup_crowdSituation(id,spotName,spotCode,realtimeNumber,totalNumber,createTime,updateTime,dataSources,remarks) values(?,?,?,?,?,?,?,?,?)";
        update(sql, new Object[]{sysrefinedcrowd.getId(), sysrefinedcrowd.getSpotName(), sysrefinedcrowd.getSpotCode(), sysrefinedcrowd.getRealtimeNumber(), sysrefinedcrowd.getTotalNumber(), sysrefinedcrowd.getCreateTime(), sysrefinedcrowd.getUpdateTime(), sysrefinedcrowd.getDataSources(), sysrefinedcrowd.getRemarks()});
    }

    @Override
    public SysRefinedCrowdSituation getMaxNumberBySysRefinedCrowdSituation(String spotCode, String starttime, String endTime) {
        String sql = "select * from sys_refined_crowdSituation where spotCode =? and createTime BETWEEN ? and ? ORDER BY realtimeNumber desc limit 0,1";
        return getEntry(sql, new SysRefinedCrowdSituationRowMapper(), new Object[]{spotCode, starttime, endTime});
    }

    @Override
    public SysRefinedCrowdSituation getRealNumberBySysRefinedCrowdSituation(String spotCode) {
        String sql = "select * from sys_refined_crowdSituation where spotCode =?  ORDER BY createTime desc limit 0,1";
        return getEntry(sql, new SysRefinedCrowdSituationRowMapper(), new Object[]{spotCode});
    }

    @Override
    public void updateHpScenicState(SysHpScenicState sysHpScenicState) {
        String sql = "update hp_scenic_state set realTimeNumber=?,totalNumber=?,maxNumber=?,maxTime=?,peopleDensity=?,riskLevel=?,recordTime=?,update_time=? where spotCode=?";
        update(sql, new Object[]{sysHpScenicState.getRealTimeNumber(), sysHpScenicState.getTotalNumber(), sysHpScenicState.getMaxNumber(), sysHpScenicState.getMaxTime(), sysHpScenicState.getPeopleDensity(), sysHpScenicState.getRiskLevel(), sysHpScenicState.getRecordTime(), new Date(), sysHpScenicState.getSpotCode()});
    }

    @Override
    public SysRefinedCrowdSituation getDateNumberBySysRefinedCrowdSituation(String spotCode, String starttime, String endTime) {
        String sql = "select * from sys_refined_crowdSituation where spotCode=? and createTime >=? and createTime <=? ORDER BY createTime DESC LIMIT 0,1";
        return getEntry(sql, new SysRefinedCrowdSituationRowMapper(), new Object[]{spotCode, starttime, endTime});
    }

    @Override
    public SysRefinedCrowdSituation getDateRealNumberBySysRefinedCrowdSituation(String spotCode, String starttime, String endTime) {
        String sql = "select * from sys_refined_crowdSituation where spotCode=? and createTime >=? and createTime <=? ORDER BY realtimeNumber DESC LIMIT 0,1";
        return getEntry(sql, new SysRefinedCrowdSituationRowMapper(), new Object[]{spotCode, starttime, endTime});
    }

    @Override
    public SysHistoryCrowdSituation getFirstSysHistoryCrowdSituation(String spotCode, String todayZero) {
        String sql = "select * from sys_history_crowdSituation where spotCode=? and recordTime=? LIMIT 1";
        return getEntry(sql, new SysHistoryCrowdSituationRowMapper(), new Object[]{spotCode, todayZero});
    }

    @Override
    public void updateHistoryCrowdSituation(SysHistoryCrowdSituation hy) {

        String sql = "update sys_history_crowdSituation set spotName=?,spotCode=?,maxTime=?,recordTime=?,maxNumber=?,totalNumber=?,warningNumber=?,dataSources=? where  id=?";

        update(sql, new Object[]{hy.getSpotName(), hy.getSpotCode(), hy.getMaxTime(), hy.getRecordTime(), hy.getMaxNumber(), hy.getTotalNumber(), hy.getWarningNumber(), hy.getDataSources(), hy.getId()});

    }

    @Override
    public void insertHistoryCrowdSituation(SysHistoryCrowdSituation hy) {

        String sql = "insert into sys_history_crowdSituation(id,spotName,spotCode,maxTime,recordTime,maxNumber,totalNumber,warningNumber,dataSources) values(?,?,?,?,?,?,?,?,?)";
        update(sql, new Object[]{hy.getId(), hy.getSpotName(), hy.getSpotCode(), hy.getMaxTime(), hy.getRecordTime(), hy.getMaxNumber(), hy.getTotalNumber(), hy.getWarningNumber(), hy.getDataSources()});

    }

    @Override
    public boolean checkParkData(QzJGWPARKData park) {
        String sql = "select * from hp_park where parkId=?";
        SysHpPark parkdata = getEntry(sql, new SysHpParkRowMapper(), new Object[]{park.getPARKID()});
        if (null != parkdata) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public void insertHpPark(SysHpPark hp_park) {
        String sql = "insert into  hp_park(parkId,spotCode,parkName,parkAddress) values(?,?,?,?)";
        update(sql, new Object[]{hp_park.getParkId(), hp_park.getSpotCode(), hp_park.getParkName(), hp_park.getParkAddress()});
    }

    @Override
    public SysHpParkInfo getSysHpParkInfo(String parkid) {
        String sql = "select * from hp_park_info where parkId=?";
        return getEntry(sql, new SysHpParkInfoRowMapper(), new Object[]{parkid});
    }

    @Override
    public void insertSysHpParkInfo(SysHpParkInfo sysHpParkInfo) {
        String sql = "insert into  hp_park_info(id,parkId,total,total_left,parkingNumber,recordTime,updateTime) values(?,?,?,?,?,?,?)";
        update(sql, new Object[]{sysHpParkInfo.getId(), sysHpParkInfo.getParkId(), sysHpParkInfo.getTotal(), sysHpParkInfo.getTotal_left(), sysHpParkInfo.getParkingNumber(), sysHpParkInfo.getRecordTime(), sysHpParkInfo.getUpdateTime()});

    }

    @Override
    public void updateSysHpParkInfo(SysHpParkInfo sysHpParkInfo) {
        String sql = "update hp_park_info set parkId=?,total=?,total_left=?,parkingNumber=?,recordTime=?,updateTime=? where id=?";
        update(sql, new Object[]{sysHpParkInfo.getParkId(), sysHpParkInfo.getTotal(), sysHpParkInfo.getTotal_left(), sysHpParkInfo.getParkingNumber(), sysHpParkInfo.getRecordTime(), sysHpParkInfo.getUpdateTime(), sysHpParkInfo.getId()});
    }

    @Override
    public List<String> getRoadIdsFromHpRoadConditionByRoadName(String[] roadNames) {
        String str = "";
        if (roadNames != null) {
            for (String roadname : roadNames) {
                // 根据
                str = str + "'" + roadname + "'" + ",";
            }
            str = str.substring(0, str.length() - 1);
        }
        String sql = "select DISTINCT roadId  from hp_road_condition where roadName in (" + str + ")";
        return queryStringArray(sql, new Object[]{});
    }

    @Override
    public void insertNewSysHpBuilding(QzSysBuildingInfo ou) {
        String sql = "insert into sys_building_info(uuid,name,amount,area,contractor,construction_unit,type,features,principal,adderss,Longitude,Latitude,inserttime,createtime) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        update(sql, new Object[]{ou.getUuid(), ou.getName(), ou.getAmount(), ou.getArea(), ou.getContractor(), ou.getConstruction_unit(), ou.getType(), ou.getFeatures(), ou.getPrincipal(), ou.getAddress(), ou.getLongitude(), ou.getLatitude(), new Date(), ou.getCreatetime()});
    }

    @Override
    public String getSysHpBuildingIdByUUId(String uuid) {
        String sql = "select id from sys_building_info where uuid=?";
        return queryString(sql, new Object[]{uuid});
    }

    @Override
    public void insertOrUpdateRoadPredictionInfo(SysHpRoadConditionInfo ro) {

        String sql = "select roadId from hp_road_condition_info where roadId=?";
        String id = queryString(sql, new Object[]{ro.getRoadId()});
        if (StringUtil.isEmpty(id)) {
            sql = "insert into hp_road_condition_info(roadId,roadLevel,nostopSpeed,speed,recordTime,updateTime,len,nostop_travel_time,travel_time) values(?,?,?,?,?,?,?,?,?)";
            update(sql, new Object[]{ro.getRoadId(), ro.getRoadLevel(), ro.getNostopSpeed(), ro.getSpeed(), ro.getRecordTime(), ro.getUpdateTime(),ro.getLen(),ro.getNostop_travel_time(),ro.getTravel_time()});

        } else {
            sql = "update  hp_road_condition_info set roadLevel=?,nostopSpeed=?,speed=?,recordTime=?,updateTime=?,len=?,nostop_travel_time=?,travel_time=? where roadId=?";
            update(sql, new Object[]{ro.getRoadLevel(), ro.getNostopSpeed(), ro.getSpeed(), ro.getRecordTime(), ro.getUpdateTime(),ro.getLen(),ro.getNostop_travel_time(),ro.getTravel_time(),ro.getRoadId()});

        }


    }

    @Override
    public boolean checkSubwayData(String zdid, String s) {

        String sql = "select * from hp_subway where subwayId=? and spotCode=?";
        HpSubway hpSubway = getEntry(sql, new HpSubWayRowMapper(), new Object[]{zdid, s});
        if (null != hpSubway) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public void updateHpSubway(HpSubway hpSubway) {

    }

    @Override
    public void insertHpSubway(HpSubway hpSubway) {
        String sql = "insert into hp_subway(id,subwayId,subway_exit_number,spotCode,subwayName,subwayLine,gd_jd,gd_wd)values(?,?,?,?,?,?,?,?)";
        update(sql, new Object[]{hpSubway.getId(), hpSubway.getSubwayId(), hpSubway.getSubway_exit_number(), hpSubway.getSpotCode(), hpSubway.getSubwayName(), hpSubway.getSubwayLine(), hpSubway.getGd_jd(), hpSubway.getGd_wd()});
    }

    @Override
    public void insertOrUpdatesubwayExitInfo(HpSubwayExitInfo sb) {

        String sql="select id from hp_subway_exit_sys where spotcode=? and create_time=?";
        String id=queryString(sql,new Object[]{sb.getSpotCode(),sb.getCreate_time()});

        if(StringUtils.isEmpty(id)){
            sql = "insert into hp_subway_exit_sys(spotCode,inTotalNum,outTotalNum,subwayId,create_time,zdmc)values(?,?,?,?,?,?)";
            update(sql, new Object[]{sb.getSpotCode(),sb.getInTotalNum(), sb.getOutTotalNum(), sb.getSubwayId(),sb.getCreate_time(), sb.getZdmc()});

        }else{
            sql = "update hp_subway_exit_sys set spotCode=?,inTotalNum=?,outTotalNum=?,subwayId=?,create_time=?,zdmc=? where id=?";
            update(sql, new Object[]{sb.getSpotCode(),sb.getInTotalNum(), sb.getOutTotalNum(), sb.getSubwayId(),sb.getCreate_time(),sb.getZdmc(),id});

        }

    }

    @Override
    public List<String> getRoadIdsBySpotCode(String spotCode) {
        String spotCodeSql = "select roadId from hp_road_condition where spotCode =?";
        return queryStringArray(spotCodeSql,new Object[]{spotCode});
    }

    @Override
    public void insertOrUpdateRoadPrediction(SysHpRoadPrediction ro) {
        String sql = "select roadId from hp_road_prediction where roadId=? and predTime=?";
        String id = queryString(sql, new Object[]{ro.getRoadId(),ro.getPredTime()});
        if (StringUtil.isEmpty(id)) {
            sql = "insert into hp_road_prediction(roadId,spotCode,predTime,speed,congestionIndex,volIn,stepIndex,updateTime) values(?,?,?,?,?,?)";
            update(sql, new Object[]{ro.getRoadId(), ro.getSpotCode(),ro.getPredTime(),ro.getSpeed(),ro.getCongestionIndex(),ro.getVolIn(),ro.getStepIndex(), ro.getUpdateTime()});

        } else {
            sql = "update  hp_road_prediction set spotCode=?,speed=?,congestionIndex=?,volIn=?,stepIndex=?,updateTime=? where roadId=? and predTime=?";
            update(sql, new Object[]{ro.getSpotCode(),ro.getSpeed(),ro.getCongestionIndex(),ro.getVolIn(),ro.getStepIndex(), ro.getUpdateTime(), ro.getRoadId(),ro.getPredTime()});

        }
    }

    @Override
    public void insertSysHpEmergencyEvent(SysHpEmergencyEvent s) {

        String sql="select id from hp_emergency_event where eventId=?";
        String id = queryString(sql, new Object[]{s.getEventId()});
        if (StringUtil.isEmpty(id)) {
            sql = "insert into hp_emergency_event(eventId,eventName,eventTime,eventType,updateTime,BaiduLongitude,BaiduLatitude,address,startTime,endTime,eventDepartment,eventContent,connectMobile,connectName) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            update(sql, new Object[]{s.getEventId(),s.getEventName(),s.getEventTime(),s.getEventType(),new Date(),s.getBaiduLongitude(),s.getBaiduLatitude(),s.getAddress(),s.getStartTime(),s.getEndTime(),s.getEventDepartment(),s.getEventcontent(),s.getConnectMobile(),s.getConnectName()});
            sql="update sys_setting set syssettingnum=? where syssettingname=hp_emergency_event";
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            update(sql,new Object[]{sdf.format(s.getEventTime())});
        }

    }

    @Override
    public String getSysSettingByEmergencyEvent() {
        String sql="select syssettingnum from sys_setting where syssettingname=?";
        return queryString(sql,new Object[]{"hp_emergency_event"});
    }

    @Override
    public void
    insertSysSettingByEmergencyEvent(String eventTime) {
        String sql="update sys_setting set syssettingnum=? where syssettingname=?";
        update(sql,new Object[]{eventTime,"hp_emergency_event"});
    }

    @Override
    public List<String> getRoadIdsFromHpRoadCondition() {
        String sql="select rid from hp_road";
        return queryStringArray(sql,new Object[]{});
    }


    @Override
    public void insertKeLiuShuSan(String t_4k, String t_10k, String t_20k, String flows,int sum) {
        String sql ="insert into alidata_flows (four,ten,twt,flows,sum) values(?,?,?,?,?)";
        update(sql,new Object[]{t_4k,t_10k,t_20k,flows,sum});
    }

    @Override
    public int selectOne() {
        String sql="select realtimeNumber from sys_refined_crowdSituation order by createTime desc limit 1";
        return queryInteger(sql,new Object[]{});
    }

    @Override
    public void insertAlibabaWt(String content, String wt) {
        String sql="insert into alidata_wt(personcount,create_time,type) values(?,?,?)";
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(new Date());
        update(sql,new Object[]{content,format,wt});
    }

    @Override
    public void insertAlibabaPred(String trim, String dateTime) {
        String sql="insert into alidata_pred (count,creatTime) values(?,?)";
        update(sql,new Object[]{trim,dateTime});
    }

    @Override
    public void truncate(String age) {
        switch (age) {
            case "age":  String sql = "truncate table hp_syrk_age_distribute ";
            update(sql,new Object[]{});
                break;
            case "gender":  String sql1 = "truncate table hp_syrk_gender ";
                update(sql1,new Object[]{});
                break;
            case "house":  String sql2 = "truncate table hp_syrk_house_statistics  ";
                update(sql2,new Object[]{});
                break;
            case "popu":  String sql3 = "truncate table hp_syrk_hp_popu  ";
                update(sql3,new Object[]{});
                break;
            case "distribution":  String sql4 = "truncate table hp_syrk_popu_distribution  ";
                update(sql4,new Object[]{});
                break;
            case "street":  String sql5 = "truncate table hp_syrk_street ";
                update(sql5,new Object[]{});
                break;
        }
    }

    @Override
    @Transactional
    public void insertPeopleGenderById(HpSyrkGender e) {
        String sql1 = "insert into hp_syrk_gender(age_cnts,ly,sz,times) values(?,?,?,?) ";
        update(sql1, new Object[]{e.getAge_cnts(),e.getLy(),e.getSz(),e.getTimes()});
    }

    @Override
    @Transactional
    public void insertPeopleAgeById(HpSyrkAgeDistribute e) {
        String sql = "insert into  hp_syrk_age_distribute (age_distribute,sz,cjrq) values(?,?,?) ";
        update(sql, new Object[]{e.getAge_distribute(),e.getSz(),e.getCjrq()});
    }

    @Override
    @Transactional
    public void insertPeopleById(HpPersonHouseStatistics e, String age) {
        switch (age) {
            case "house":  String sql2 = " insert into hp_syrk_house_statistics (mc,sz,ly,jd,cjrq,data_operatedate,data_operatetype,service_dt,data_src,sys_load_dt,is_reload,sys_reload_dt,date_id) values(?,?,?,?,?,?,?,?,?,?,?,?,?) ";
                update(sql2, new Object[]{e.getMc(),e.getSz(), e.getLy(),e.getJd(),e.getCjrq(),e.getData_operatedate(),e.getData_operatetype(),e.getService_dt(),e.getData_src(),e.getSys_load_dt(),e.getIs_reload(),e.getSys_reload_dt(),e.getDate_id()});break;
            case "popu":  String sql3 = " insert into hp_syrk_hp_popu (mc,sz,ly,jd,cjrq,data_operatedate,data_operatetype,service_dt,data_src,sys_load_dt,is_reload,sys_reload_dt,date_id) values(?,?,?,?,?,?,?,?,?,?,?,?,?) ";
                update(sql3, new Object[]{e.getMc(),e.getSz(), e.getLy(),e.getJd(),e.getCjrq(),e.getData_operatedate(),e.getData_operatetype(),e.getService_dt(),e.getData_src(),e.getSys_load_dt(),e.getIs_reload(),e.getSys_reload_dt(),e.getDate_id()});break;
            case "distribution":  String sql4 = "insert into hp_syrk_popu_distribution (mc,sz,ly,jd,cjrq,data_operatedate,data_operatetype,service_dt,data_src,sys_load_dt,is_reload,sys_reload_dt,date_id) values(?,?,?,?,?,?,?,?,?,?,?,?,?) ";
                update(sql4, new Object[]{e.getMc(),e.getSz(), e.getLy(),e.getJd(),e.getCjrq(),e.getData_operatedate(),e.getData_operatetype(),e.getService_dt(),e.getData_src(),e.getSys_load_dt(),e.getIs_reload(),e.getSys_reload_dt(),e.getDate_id()});break;
            case "street":  String sql5 = "insert into  hp_syrk_street (mc,sz,ly,jd,cjrq,data_operatedate,data_operatetype,service_dt,data_src,sys_load_dt,is_reload,sys_reload_dt,date_id) values(?,?,?,?,?,?,?,?,?,?,?,?,?) ";
                update(sql5, new Object[]{e.getMc(),e.getSz(), e.getLy(),e.getJd(),e.getCjrq(),e.getData_operatedate(),e.getData_operatetype(),e.getService_dt(),e.getData_src(),e.getSys_load_dt(),e.getIs_reload(),e.getSys_reload_dt(),e.getDate_id()});break;
        }
    }

    @Override
    public String getId( String cjrq,String age) {
        switch (age) {
            case "age":  String sql = "select cjrq from hp_syrk_age_distribute where cjrq=? ";
            return queryString(sql, new Object[]{cjrq});
            case "gender":  String sql1 = "select times from hp_syrk_gender where times=? ";
                return queryString(sql1, new Object[]{cjrq});
            case "house":  String sql2 = "select cjrq from hp_syrk_house_statistics where cjrq=? ";
                return queryString(sql2, new Object[]{cjrq});
            case "popu":  String sql3 = "select cjrq from hp_syrk_hp_popu where cjrq=? ";
                return queryString(sql3, new Object[]{cjrq});
            case "distribution":  String sql4 = "select cjrq from hp_syrk_popu_distribution where cjrq=? ";
                return queryString(sql4, new Object[]{cjrq});
            case "street":  String sql5 = "select cjrq from hp_syrk_street where cjrq=? ";
                return queryString(sql5, new Object[]{cjrq});
        }
        return  null;
    }

    @Override
    public void insertNjdlTotalNumber(NjdlTotalNumber number) {
        String sql="insert into nanjing_total_number(spotName,times,total_number) values(?,?,?)";
        update(sql,new Object[]{number.getSpotName(),number.getTimes(),number.getTotal_number()});
    }

    @Override
    public NjdlTotalNumber findNjdlTotaolNumber(String times) {
        String sql="select * from nanjing_total_number where times=?";
        return getEntry(sql,new NjdlTotalNumberRowMapper(),new Object[]{times});
    }

    @Override
    public List<NjdlTotalNumber> getNjdlTotalNumberTask() {
        String sql="SELECT spotName,substr( times, 1, 10 ) AS times,sum( max_cnts ) AS total_number " +
                " FROM (SELECT CONCAT(DATE_FORMAT( createTime, '%Y-%m-%d %H ' ),CASE WHEN MINUTE ( createTime )<= 20 THEN '上' WHEN MINUTE ( createTime ) >= 20 AND MINUTE ( createTime ) <= 40 THEN '中' ELSE '下' END ) AS times, max( realtimeNumber ) AS max_cnts, spotName FROM sys_refined_crowdSituation WHERE spotName = '南京路' AND createTime >= '2018-11-19 00:00:00' AND createTime <= DATE_SUB( DATE_ADD(CURRENT_DATE()-1, INTERVAL 1 DAY),INTERVAL 1 SECOND)  \n" +
                " GROUP BY CONCAT(DATE_FORMAT( createTime, '%Y-%m-%d %H ' ),CASE WHEN MINUTE ( createTime )<= 20 THEN '上' WHEN MINUTE ( createTime ) >= 20 AND MINUTE ( createTime ) <= 40 THEN '中' ELSE '下' END )) tmp GROUP BY substr( times, 1, 10 ),spotName";
        return getEntryList(sql,new NjdlTotalNumberRowMapper(),new Object[]{});
    }

    @Override
    public void updateBlmqOwnCheckList(BlmqOwnCheckList b) {
        String sql="update  hp_ownwe_check_list set BUILD_ID=?,YEAR=?,OPERABLE_VENT=?,SEALANT=?,GLASS=?,FORCE_MEMBER=?," +
                "RAIN=?,ADD_TIME=?,CREATE_TIME=? where ID=? ";
        update(sql,new Object[]{b.getBUILD_ID(),b.getYEAR(),b.getWINDOW(),b.getSEALANT(),
                b.getGLASS(),b.getFORCE(),b.getRAIN(),b.getADD_TIME(),b.getCREATE_TIME(),b.getID()});
    }

    @Override
    public void insertBlmqOwnCheckList(BlmqOwnCheckList b) {
        String sql="insert into hp_ownwe_check_list(ID,BUILD_ID,YEAR,OPERABLE_VENT,SEALANT,GLASS,FORCE_MEMBER," +
                "RAIN,ADD_TIME,CREATE_TIME) " +
                "values(?,?,?,?,?,?,?,?,?,?)";
        update(sql,new Object[]{b.getID(),b.getBUILD_ID(),b.getYEAR(),b.getWINDOW(),b.getSEALANT(),
        b.getGLASS(),b.getFORCE(),b.getRAIN(),b.getADD_TIME(),b.getCREATE_TIME()});
    }

    @Override
    public void updateBlmqEmergencyDtl(BlmqEmergencyDtl b) {
        String sql="update  hp_emergency_dtl set CHECK_LISE_ID=?,DANGER_SITE_URL=?,WARNING_URL=?,WARNING_DATE=?,CREATE_TIME=? where ID=?"
                ;
        update(sql,new Object[]{b.getCHECK_LISE_ID(),b.getDANGER_SITE_URL(),b.getWARNING_URL(),
                b.getWARNING_DATE(),b.getCREATE_TIME(),b.getID()});
    }

    @Override
    public void insertBlmqEmergencyDtl(BlmqEmergencyDtl b) {
        String sql="insert into hp_emergency_dtl(ID,CHECK_LISE_ID,DANGER_SITE_URL,WARNING_URL,WARNING_DATE,CREATE_TIME) " +
                "values(?,?,?,?,?,?)";
        update(sql,new Object[]{b.getID(),b.getCHECK_LISE_ID(),b.getDANGER_SITE_URL(),b.getWARNING_URL(),
                b.getWARNING_DATE(),b.getCREATE_TIME()});
    }

    @Override
    public void updateBlmqCountryCheck(BlmqCountryCheck c) {
        String sql="update  hp_county_check_count set CHECK_YEAR=?,ALL_NUM=?,CHECK_NUM=?,RETIFIED_NUM=?,CASE_CLOSE_NUM=?,CREATE_TIME=? where ID=? " ;
        update(sql,new Object[]{c.getYEAR(),c.getALL_NUM(),c.getCHECK_NUM(),c.getRETIFIED_NUM(),
                c.getCASE_CLOSE_NUM(),c.getCREATE_TIME(),c.getID()});
    }

    @Override
    public void insertBlmqCountryCheck(BlmqCountryCheck c) {
        String sql="insert into hp_county_check_count(ID,CHECK_YEAR,ALL_NUM,CHECK_NUM,RETIFIED_NUM,CASE_CLOSE_NUM,CREATE_TIME) " +
                "values(?,?,?,?,?,?,?)";
        update(sql,new Object[]{c.getID(),c.getYEAR(),c.getALL_NUM(),c.getCHECK_NUM(),c.getRETIFIED_NUM(),
                c.getCASE_CLOSE_NUM(),c.getCREATE_TIME()});
    }

    @Override
    public void updateCheckListLogBulidInfo(BlmqCheckListLog l) {
        String sql="update  hp_check_list_log set CHECK_LIST_ID=?,FIND=?,FIND_TIME=?,CONFIRM=?,CONFIRM_TIME=?,SEND=?,SEND_TIME=?," +
                "EMERGENCY=?,EMERGENCY_TIME=?,RECTIFY=?,RECTIFY_TIME=?,INSPECT=?,INSPECT_TIME=?,CASE_CLOSE=?,CASE_CLOSE_TIME=?,CREATE_TIME=?,LAST_DATE=? where ID=?" ;
        update(sql,new Object[]{l.getCHECK_LISE_ID(),l.getFIND(),l.getFIND_TIME(),l.getCONFIRM(),l.getCONFIRM_TIME(),
                l.getSEND(),l.getSEND_TIME(),l.getEMERGENCY(),l.getEMERGENCY_TIME(),l.getRECTIFY(),l.getRECTIFY_TIME(),l.getINSPECT(),
                l.getINSPECT_TIME(),l.getCASE_CLOSE(),l.getCASE_CLOSE_TIME(),l.getCreate_time(),l.getLAST_DATE(),l.getID()});
    }

    @Override
    public void insertCheckListLogBulidInfo(BlmqCheckListLog l) {
        String sql="insert into hp_check_list_log(ID,CHECK_LIST_ID,FIND,FIND_TIME,CONFIRM,CONFIRM_TIME,SEND,SEND_TIME," +
                "EMERGENCY,EMERGENCY_TIME,RECTIFY,RECTIFY_TIME,INSPECT,INSPECT_TIME,CASE_CLOSE,CASE_CLOSE_TIME,CREATE_TIME) " +
                "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        update(sql,new Object[]{l.getID(),l.getCHECK_LISE_ID(),l.getFIND(),l.getFIND_TIME(),l.getCONFIRM(),l.getCONFIRM_TIME(),
        l.getSEND(),l.getSEND_TIME(),l.getEMERGENCY(),l.getEMERGENCY_TIME(),l.getRECTIFY(),l.getRECTIFY_TIME(),l.getINSPECT(),
        l.getINSPECT_TIME(),l.getCASE_CLOSE(),l.getCASE_CLOSE_TIME(),l.getCreate_time()});
    }

    @Override
    public void updateCheckListDtlBulidInfo(BlmqCheckListDtl c) {
        String sql="update hp_check_list_dtl set CHECK_LIST_ID=?,DAMAGE_TYPE=?,DAMAGE_URL=?,DEMAGE_SITE=?,CREATE_TIME=? where ID=? ";
        update(sql,new Object[]{c.getCHECK_LIST_ID(),c.getDAMAGE_TYPE(),c.getDAMAGE_URL(),c.getDEMAGE_SITE(),
                c.getCREATE_TIME(),c.getID()});
    }

    @Override
    public void insertCheckListDtlBulidInfo(BlmqCheckListDtl c) {
        String sql="insert into hp_check_list_dtl(ID,CHECK_LIST_ID,DAMAGE_TYPE,DAMAGE_URL,DEMAGE_SITE,CREATE_TIME) values(?,?,?,?,?,?)";
        update(sql,new Object[]{c.getID(),c.getCHECK_LIST_ID(),c.getDAMAGE_TYPE(),c.getDAMAGE_URL(),c.getDEMAGE_SITE(),
        c.getCREATE_TIME()});
    }

    @Override
    public BlmqOwnCheckList findBlmqOwnCheckListById(String id) {
        String sql="select * from hp_ownwe_check_list where id=?";
        return getEntry(sql,new BlmqOwnCheckListRowMapper(), new Object[]{id});
    }

    @Override
    public BlmqEmergencyDtl findBlmqEmergencyDtlById(String id) {
        String sql="select * from hp_emergency_dtl where id=?";
        return getEntry(sql,new BlmqEmergencyDtlRowMapper(), new Object[]{id});
    }

    @Override
    public BlmqCountryCheck findBlmqCountryCheckById(String id) {
        String sql="select * from hp_county_check_count where id=?";
        return getEntry(sql,new BlmqCountryCheckRowMapper(), new Object[]{id});
    }

    @Override
    public BlmqCheckListLog findCheckListLogById(String id) {
        String sql="select * from hp_check_list_log where id=?";
        return getEntry(sql,new BlmqCheckListLogRowMapper(), new Object[]{id});
    }

    @Override
    public BlmqCheckListDtl findCheckListDtlById(String id) {
        String sql="select * from hp_check_list_dtl where id=?";
        return getEntry(sql,new BlmqCheckListDtlRowMapper(), new Object[]{id});
    }

    @Override
    public void updateCheckListBulidInfo(BlmqCheckList b) {
        String sql="update hp_check_list set build_id=?,check_year=?,check_time=?,need_change=?,found_issues=?,build_tag=?,confirm_sheet=?,high_deop_risk=?,create_time1=?,last_time=?,check_status=? where ID=?";
        update(sql, new Object[]{b.getBUILD_ID(),b.getYEAR(),b.getCHECK_TIME(),b.getNEED_CHANGE(),
                b.getFOUND_ISSUES(),b.getBUILD_TAG(),b.getCONFIRM_SHEET(),b.getHIGH_DEOP_RISK(),b.getCREATE_TIME1(),b.getLAST_TIME(),
                b.getCHECK_STATUS(),b.getID()});
    }

    @Override
    public void insertCheckListBulidInfo(BlmqCheckList b) {
        String sql="insert into hp_check_list(ID,build_id,check_year,check_time,need_change,found_issues," +
                "build_tag,confirm_sheet,high_deop_risk,create_time1,last_time,check_status) values(?,?,?,?,?,?,?,?,?,?,?,?)";
        update(sql,new Object[]{b.getID(),b.getBUILD_ID(),b.getYEAR(),b.getCHECK_TIME(),b.getNEED_CHANGE(),
        b.getFOUND_ISSUES(),b.getBUILD_TAG(),b.getCONFIRM_SHEET(),b.getHIGH_DEOP_RISK(),b.getCREATE_TIME1(),b.getLAST_TIME(),
        b.getCHECK_STATUS()});
    }

    @Override
    public BlmqCheckList findCheckListById(String id) {
        String sql="select * from hp_check_list where id=?";
        return getEntry(sql,new BlmqCheckListRowMapper(), new Object[]{id});
    }

    @Override
    @Transactional
    public void updateBulidInfo(BlmqBuildInfo f) {
        String sql="update hp_build_info set build_name=?,build_addr=?,village=?,area_code=?,use_nature=?," +
                "building_high=?,building_age=?,building_sort=?,complete_date=?,owner_name=?,owner_tel=?,owner_unit=?," +
                "property=?,property_name=?,property_tel=?,build_dxrerior=?,wall_high=?,wall_area=?,wall_life=?,wall_date=?," +
                "structure=?,wall_type=?,glass_type=?,wall_dxrerior=?,next_check_time=?,build_tag=?,longitude=?," +
                "latitude=?,create_time1=?,last_time=?,jhpt_update_time=?,jhpt_delete=?,data_operatedate=?,data_operatetype=?,service_dt=?,data_src=?," +
                "sys_load_dt=?,is_reload=?,sys_reload_dt=?,date_id=? where build_id=?";
        update(sql,new Object[]{f.getBUILD_NAME(),f.getBUILD_ADDR(),f.getVILLAGE(),f.getAREA_CODE(),
                f.getUSE_NATURE(),f.getBUILDING_HIGH(),f.getBUILDING_AGE(),f.getBUILDING_SORT(),f.getCOMPLETE_DATE(),
                f.getOWNER_NAME(),f.getOWNER_TEL(),f.getOWNER_UNIT(),f.getPROPERTY(),f.getPROPERTY_NAME(),f.getPROPERTY_TEL(),
                f.getBUILD_DXRERIOR(),f.getWALL_HIGH(),f.getWALL_AREA(),f.getWALL_LIFE(),f.getWALL_DATE(),f.getSTRUCTURE(),
                f.getWALL_TYPE(),f.getGLASS_TYPE(),f.getWALL_DXRERIOR(),f.getNEXT_CHECK_TIME(),f.getBUILD_TAG(),f.getLONGITUDE(),
                f.getLATITUDE(),f.getCREATE_TIME1(),f.getLast_time(),f.getJhpt_update_time(),f.getJhpt_delete(),f.getData_operatedate(),
                f.getData_operatetype(),f.getService_dt(),f.getData_src(),f.getSys_load_dt(),f.getIs_reload(),f.getSys_reload_dt(),f.getDate_id(),f.getBUILD_ID()});
    }

    @Override
    @Transactional
    public void insertBulidInfo(BlmqBuildInfo f) {
        String sql="insert into hp_build_info(build_id,build_name,build_addr,village,area_code,use_nature," +
                "building_high,building_age,building_sort,complete_date,owner_name,owner_tel,owner_unit," +
                "property,property_name,property_tel,build_dxrerior,wall_high,wall_area,wall_life,wall_date," +
                "structure,wall_type,glass_type,wall_dxrerior,next_check_time,build_tag,longitude," +
                "latitude,create_time1,last_time,jhpt_update_time,jhpt_delete,data_operatedate,data_operatetype,service_dt,data_src," +
                "sys_load_dt,is_reload,sys_reload_dt,date_id) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        update(sql,new Object[]{f.getBUILD_ID(),f.getBUILD_NAME(),f.getBUILD_ADDR(),f.getVILLAGE(),f.getAREA_CODE(),
        f.getUSE_NATURE(),f.getBUILDING_HIGH(),f.getBUILDING_AGE(),f.getBUILDING_SORT(),f.getCOMPLETE_DATE(),
        f.getOWNER_NAME(),f.getOWNER_TEL(),f.getOWNER_UNIT(),f.getPROPERTY(),f.getPROPERTY_NAME(),f.getPROPERTY_TEL(),
        f.getBUILD_DXRERIOR(),f.getWALL_HIGH(),f.getWALL_AREA(),f.getWALL_LIFE(),f.getWALL_DATE(),f.getSTRUCTURE(),
        f.getWALL_TYPE(),f.getGLASS_TYPE(),f.getWALL_DXRERIOR(),f.getNEXT_CHECK_TIME(),f.getBUILD_TAG(),f.getLONGITUDE(),
        f.getLATITUDE(),f.getCREATE_TIME1(),f.getLast_time(),f.getJhpt_update_time(),f.getJhpt_delete(),f.getData_operatedate(),
        f.getData_operatetype(),f.getService_dt(),f.getData_src(),f.getSys_load_dt(),f.getIs_reload(),f.getSys_reload_dt(),f.getDate_id()});
    }

    @Override
    public BlmqBuildInfo findById(Integer build_id) {
        String sql="select * from hp_build_info where build_id=?";
        return getEntry(sql,new BlmqBuildInfoRowMapper(),new Object[]{build_id});
    }

    @Override
    public void updateThreeData() {
        String sql="delete  FROM alidata_personcount WHERE DATEDIFF(create_time,NOW())<-2";
         update(sql,new Object[]{});
        String sql1="delete  FROM alidata_wt WHERE DATEDIFF(create_time,NOW())<-2";
        update(sql1,new Object[]{});
    }

    @Override
    public void insertAlibabaPersonCount(String content, String njdl) {
        String sql="insert into alidata_personcount(personcount,create_time,type) values(?,?,?)";
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(new Date());
        update(sql,new Object[]{content,format,njdl});
    }


}
